﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DomPrint.UControl;
using Framework.Common;
using DomPrint.Common;
using Framework;
using Model.Custome;

namespace DomPrint
{
    public partial class MainForm : BaseForm
    {
        #region 属性
        /// <summary>
        /// 硬盘类型
        /// </summary>
        public HDType HdType
        {
            get { return CurUCDom.hdType; }
        }
        /// <summary>
        /// 磁带类型
        /// </summary>
        public TapeType TapeType
        {
            get { return CurUCDom.tapeType; }
        }
        /// <summary>
        /// 编号列表集合
        /// </summary>
        public List<ListItemInfo> ListItem
        {
            get { return CurUCDom.ListItem; }
        }

        TabPage curPage
        {
            get { return tabControl1.TabPages[tabControl1.SelectedIndex]; }
        }

        /// <summary>
        /// 介质类型
        /// </summary>
        public MediumType MediumType
        {
            get
            {
                int mediumType = curPage.Tag.ToString().ToInt();
                return (MediumType)mediumType;
            }
        }

        /// <summary>
        /// 当前用户控件
        /// </summary>
        UCDom CurUCDom;

        #endregion

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                tabControl1_SelectedIndexChanged(null, e);
            }
            catch (Exception ex)
            {
                LogHelper.ErrorFormat("MainForm load excption:{0}{1}", ex.Message, ex.StackTrace);
                DomCommon.ShowError("程序加载出现异常");
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (curPage.Controls.Count == 0)
                {
                    CurUCDom = new UCDom(MediumType);
                    curPage.Controls.Add(CurUCDom);
                }
                else
                {
                    CurUCDom = curPage.Controls[0] as UCDom;
                }
                ucSetting1.TypeName = MediumType;
            }
            catch (Exception ex)
            {
                LogHelper.ErrorFormat("Tab selected index changed excption:{0}{1}", ex.Message, ex.StackTrace);
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DomCommon.ShowAsk("是否确定退出程序?") == DialogResult.Yes)
                LogHelper.Info("Program exit.");
            else
                e.Cancel = true;
        }


    }
}
